package com.zcf.service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zcf.common.json.Body;
import com.zcf.mapper.ServiceMapper;
import com.zcf.vo.out.LayuiJson;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhaoQi
 * @since 2019-03-18
 */
@Service
public class ServiceServiceImpl{

	@Autowired
	ServiceMapper sm;
	/**
	 * 后端获取客服信息
	 * @return
	 */
	public LayuiJson getService() {
		LayuiJson lj = new LayuiJson();
		List<com.zcf.pojo.Service> list = new ArrayList<>();
		com.zcf.pojo.Service service =  sm.selectById(1);
		if(service!=null){
			 lj.setCode(0);
	            lj.setCount(1);
	            lj.setMsg("yes");
	            list.add(service);
	            lj.setData(list);
	            return lj;
		}
		lj.setCode(1);
        lj.setCount(0);
        lj.setMsg("no data");
        lj.setData(null);
        return lj;
	}
	/**
	 * 前端获取客服信息
	 * @return
	 */
	public Body getServices() {
		com.zcf.pojo.Service service = sm.selectById(1);
		if(service == null){
			 return Body.BODY_451;
		}
		 return Body.newInstance(service);
	}
	/**
	 * 修改客服信息
	 * @param service
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	public Body update(com.zcf.pojo.Service service) {
		service.setId((long) 1);
		boolean b =  service.updateById();
		
		if(b){
//			com.zcf.pojo.Service service1 = sm.selectById(service.getId());
//			return Body.newInstance(service1);
			return Body.BODY_200;
		}
		
		return Body.BODY_451;
	}
	
	
	
	
}
